//package org.ricks.robot.business;
//
//import org.ricks.common.utils.RandomUtils;
//import org.ricks.common.utils.ThreadUtils;
//import org.ricks.net.transport.kcp.KcpSession;
//import org.ricks.protocol.ByteBuf;
//import org.ricks.robot.Monitor;
//import org.ricks.robot.RobotInfo;
//import org.ricks.robot.RobotManager;
//import org.ricks.robot.RobotRun;
//import org.ricks.robot.action.wrap.RobotEquipActionWrap;
//import proto.common.FProto;
//import proto.common.PBItem;
//import proto.common.PBItemPack;
//
//import java.util.Map;
//import java.util.Objects;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.concurrent.TimeUnit;
//import java.util.concurrent.atomic.AtomicBoolean;
//import java.util.stream.Collectors;
//
//public class RobotAction {
//
//    public static AtomicBoolean stating = new AtomicBoolean(true);
//    public static final Map<KcpSession, Long> taskTimes = new ConcurrentHashMap<>();
//
//    public static void robotStart (KcpSession aioSession) {
//
////        RobotAction.addItem(aioSession, 2111001, 1);
//
////        RobotLifeAction.startCookTask( aioSession);
//
////        RobotLifeAction.startHandicraftTask(aioSession);
////        RobotLifeAction.startSpinTask(aioSession);
////        RobotGachaAction.startGachaTask(aioSession,100);
////        RobotRoleAction.starRoleAction(aioSession);
////        RobotStageAction.startKillMonsterAction(aioSession);
////        RobotChatAction.startRobotChatAction(aioSession,10000000);
//
////        RobotEquipAction.equipStrength();
//
////        RobotEquipAction.startEquipTask(aioSession);
//
////        RobotRoleAction.starRoleAction((KcpSession) aioSession);
//
////        RobotStageAction.enterDungeonAction((KcpSession) aioSession, );
//
//
////        RobotMmoAction.syncFrameData(aioSession);
////        ThreadUtils.sleep(5000L);
//        RobotChannelAction.channelJump(aioSession);
//    }
//
//    public static void robotStop() {
//       stating.set(false);
//    }
//
//
//    public static void addItem(KcpSession session, int itemId , int count) {
//        int randomTime = RandomUtils.randomInt(1000, 5000);
//        RobotRun.scheduledExecutorService.schedule(() -> {
//            Monitor.addActionRequest(session, FProto.Action.GM);
//            RobotInfo robotInfo = RobotManager.get(session);
//            robotInfo.requestTimeMap.put(FProto.Action.GM, System.currentTimeMillis());
//            FProto fProto = FProto.newBuilder()
//                    .setKey(FProto.Key.Player)
//                    .setAction(FProto.Action.GM)
//                    .setGmCmd("itemAdd " + itemId + " " + count)
//                    .build();
//
////        Logger.info(RobotManager.get(session).toString() + " 开始增加道具Id:" + itemId + " , 道具num：" + count);
//
//            byte[] data = fProto.toByteArray();
//
//            ByteBuf buf = new ByteBuf(1024);
//            buf.writeByte((byte) 0x03);
//            buf.writeBytes(data);
//
//            session.send(buf.toArray());
//        }, randomTime, TimeUnit.MILLISECONDS);
//
//    }
//
//    public static void addArmor(KcpSession session, int armorId , int count) {
//        Monitor.addActionRequest(session, FProto.Action.GM);
//        RobotInfo robotInfo = RobotManager.get(session);
//        robotInfo.requestTimeMap.put(FProto.Action.GM, System.currentTimeMillis());
//        FProto fProto = FProto.newBuilder()
//                .setKey(FProto.Key.Player)
//                .setAction(FProto.Action.GM)
//                .setGmCmd("armorAdd " + armorId + " " + count + " 1")
//                .build();
//
////        Logger.info(RobotManager.get(session).toString() + " 开始增加道具Id:" + itemId + " , 道具num：" + count);
//
//        byte[] data = fProto.toByteArray();
//
//        ByteBuf buf = new ByteBuf(1024);
//        buf.writeByte((byte) 0x03);
//        buf.writeBytes(data);
//
//        session.send(buf.toArray());
//    }
//
//    /**
//     * @param session
//     * @param fProto
//     * @return 功能所需得道具是否全部添加完成，后续操作
//     */
//    public static void resAddItem (KcpSession session, FProto fProto) {
//        PBItemPack itemPack = fProto.getSelf().getItemPack();
//        RobotInfo robotInfo = RobotManager.get(session);
//
//        if(checkItems( robotInfo, itemPack.getItemArray(0))) {
//            switch (robotInfo.action) {
//                case CookingFood -> robotInfo.robotCookActionWrap.robotCookCmdAction.cook(session, robotInfo.robotCookActionWrap.cookId);
//                case Handicraft -> robotInfo.handicraftCmdActionWrap.handicraftCmdAction.handicraft(session, robotInfo.handicraftCmdActionWrap.handicraftId);
//                case Sewing -> robotInfo.robotSpinCmdActionWrap.spinCmdAction.spin(session, robotInfo.robotSpinCmdActionWrap.spinId);
//                case UpdateEquip -> RobotEquipAction.addEquipUpItems(session);
//                case EquipStrength -> {
//                    long equipId = fProto.getSelf().getItemPack().getArmorInstanceArray(0).getInstanceId();
//                    robotInfo.robotEquipActionWrap.equipId = equipId;
////                    RobotEquipAction.createEquipWrap(session,itemId, equipId);
//                    RobotRun.scheduledExecutorService.schedule(() -> {
//                        RobotEquipActionWrap equipActionWrap = RobotManager.get(session).robotEquipActionWrap;
//                        equipActionWrap.equipStrengthAction.equipStrength(session, equipId);
//                    },1000, TimeUnit.MILLISECONDS);
//                }
//                case Gacha -> RobotGachaAction.gacha(session, 1000);
//                case CharacterCreatePush -> {
//                    PBItem pbItem = itemPack.getItemArray(0);
//                    switch (pbItem.getItemId()) {
//                        case 101001 -> RobotAction.addItem(session, 101002, 1);
//                        case 101002 -> RobotAction.addItem(session, 101003, 1);
//                        case 101003 -> RobotAction.addItem(session, 101004, 1);
//                        case 101004 -> RobotAction.addItem(session, 101005, 1);
//                        case 101005 -> RobotAction.addItem(session, 102001, 1);
//                        case 102001 -> RobotAction.addItem(session, 102002, 1);
//                        case 102002 -> RobotAction.addItem(session, 102003, 1);
//                        case 102003 -> RobotAction.addItem(session, 102004, 1);
//                        case 102004 -> RobotAction.addItem(session, 102005, 1);
//                        case 102005 -> RobotAction.addItem(session, 103001, 1);
//                        case 103001 -> RobotAction.addItem(session, 103002, 1);
//                        case 103002 -> RobotAction.addItem(session, 103003, 1);
//                        case 103003 -> RobotAction.addItem(session, 103004, 1);
//                        case 103004 -> RobotAction.addItem(session, 103005, 1);
//                        case 103005 -> RobotAction.addItem(session, 1000, 1000000);
//                        case 1000 -> RobotAction.addItem(session, 1001, 1000000);
//                        case 1001 -> RobotAction.addItem(session, 1002, 1000000);
//                        case 1002 -> RobotAction.addItem(session, 1003, 1000000);
//                        case 1003 -> RobotAction.addItem(session, 1010, 1000000);
//                        case 1010 -> RobotAction.addItem(session, 1011, 1000000);
//                        case 1011 -> RobotAction.addItem(session, 1012, 1000000);
//                        case 1012 -> RobotAction.addItem(session, 1013, 1000000);
//                        case 1013 -> RobotAction.addItem(session, 1020, 1000000);
//                        case 1020 -> RobotAction.addItem(session, 1021, 1000000);
//                        case 1021 -> RobotAction.addItem(session, 1022, 1000000);
//                        case 1022 -> RobotAction.addItem(session, 1023, 1000000);
//                        case 1023 -> RobotAction.addItem(session, 1030, 1000000);
//                        case 1030 -> RobotAction.addItem(session, 1031, 1000000);
//                        case 1031 -> RobotAction.addItem(session, 1032, 1000000);
//                        case 1032 -> RobotAction.addItem(session, 1033, 1000000);
//                        case 1033 -> RobotAction.addItem(session, 101, 1000000000);
//                        case 101 -> RobotAction.addItem(session, 190, 10000000);
//                        case 190 -> RobotAction.addItem(session, 191, 100000);
//                        case 191 -> RobotAction.addItem(session, 192, 100000);
//                        case 192 -> RobotRoleAction.roleLvUpAction(session, 101001);
//                    }
//
//                }
//
//                case CharacterStarUp -> {
//                    PBItem pbItem = itemPack.getItemArray(0);
//                    switch (pbItem.getItemId()) {
//                        case 31101 -> RobotAction.addItem(session, 31102,5000);
//                        case 31102 -> RobotAction.addItem(session, 31103,5000);
//                        case 31103 -> RobotAction.addItem(session, 31104,5000);
//                        case 31104 -> RobotAction.addItem(session, 31105,5000);
//                        case 31105 -> RobotAction.addItem(session, 31201,5000);
//                        case 31201 -> RobotAction.addItem(session, 31202,5000);
//                        case 31202 -> RobotAction.addItem(session, 31203,5000);
//                        case 31203 -> RobotAction.addItem(session, 31204,5000);
//                        case 31204 -> RobotAction.addItem(session, 31205,5000);
//                        case 31205 -> RobotAction.addItem(session, 31301,5000);
//                        case 31301 -> RobotAction.addItem(session, 31302,5000);
//                        case 31302 -> RobotAction.addItem(session, 31303,5000);
//                        case 31303 -> RobotAction.addItem(session, 31304,5000);
//                        case 31304 -> RobotAction.addItem(session, 31305,5000);
//                        case 31305 -> RobotAction.addItem(session, 31401,5000);
//                        case 31401 -> RobotAction.addItem(session, 31402,5000);
//                        case 31402 -> RobotAction.addItem(session, 31403,5000);
//                        case 31403 -> RobotAction.addItem(session, 31404,5000);
//                        case 31404 -> RobotAction.addItem(session, 31405,5000);
//                        case 31405 -> RobotAction.addItem(session, 32101,5000);
//
//                        case 32101 -> RobotAction.addItem(session, 32102,5000);
//                        case 32102 -> RobotAction.addItem(session, 32103,5000);
//                        case 32103 -> RobotAction.addItem(session, 32104,5000);
//                        case 32104 -> RobotAction.addItem(session, 32105,5000);
//                        case 32105 -> RobotAction.addItem(session, 33101,5000);
//                        case 33101 -> RobotAction.addItem(session, 33102,5000);
//                        case 33102 -> RobotAction.addItem(session, 33103,5000);
//                        case 33103 -> RobotAction.addItem(session, 33104,5000);
//                        case 33104 -> RobotAction.addItem(session, 33105,5000);
//
//                        case 33105 -> RobotAction.addItem(session, 33201,5000);
//                        case 33201 -> RobotAction.addItem(session, 33202,5000);
//                        case 33202 -> RobotAction.addItem(session, 33203,5000);
//                        case 33203 -> RobotAction.addItem(session, 33204,5000);
//                        case 33204 -> RobotAction.addItem(session, 33205,5000);
//                        case 33205 ->  RobotAction.addItem(session, 34101,5000);
//                        case 34101 ->  RobotAction.addItem(session, 34102,5000);
//                        case 34102 ->  RobotAction.addItem(session, 34103,5000);
//                        case 34103 ->  RobotAction.addItem(session, 34104,5000);
//                        case 34104 ->  RobotAction.addItem(session, 34105,5000);
//                        case 34105 ->  RobotAction.addItem(session, 34201,5000);
//                        case 34201 ->  RobotAction.addItem(session, 34202,5000);
//                        case 34202 ->  RobotAction.addItem(session, 34203,5000);
//                        case 34203 ->  RobotAction.addItem(session, 34204,5000);
//                        case 34204 ->  RobotAction.addItem(session, 34205,5000);
//                        case 34205 ->  RobotAction.addItem(session, 34301,5000);
//                        case 34301 -> RobotAction.addItem(session, 34302,5000);
//                        case 34302 ->  RobotAction.addItem(session, 34303,5000);
//                        case 34303 ->  RobotAction.addItem(session, 34304,5000);
//                        case 34304 ->  RobotAction.addItem(session, 34305,5000);
//                        case 34305 -> RobotRoleAction.roleStarLvAction(session, 101001);
//                    }
//                }
//
//                case ChannelJump -> {
//
//                    Thread.ofVirtual().start(() -> {
//                       while (true) {
//                           ThreadUtils.sleep(33l);
//                           RobotMmoAction.doSyncFrameData(session);
//                       }
//                    });
////                    RobotRun.scheduledExecutorService.scheduleAtFixedRate(() -> {
////                        RobotMmoAction.doSyncFrameData( session);
////                    }, 1000L,33L, TimeUnit.MILLISECONDS);
//                }
//            }
//        }
//    }
//
//    public static boolean checkItems (RobotInfo robotInfo, PBItem item) {
//        return switch (robotInfo.action) {
//            case CookingFood -> checkCookItems(robotInfo, item);
//            case Handicraft -> checkHandicraftItems(robotInfo, item);
//            case Sewing -> checkSpinItems(robotInfo, item);
//            case UpdateEquip -> robotInfo.robotEquipActionWrap.equipItemId == item.getItemId();
//            case EquipStrength -> checkEquipStrengthItems(robotInfo,item);
//            case Gacha -> item.getItemId() == 104;
//            case CharacterCreatePush,  CharacterStarUp , DungeonEnter, SyncRecorderData , ChannelJump-> true;
//            default -> throw new RuntimeException(robotInfo + " , 触发未知机器人行为 action:" + robotInfo.action);
//        };
//    }
//
//    public static boolean checkCookItems(RobotInfo robotInfo,PBItem item) {
//        robotInfo.robotCookActionWrap.itemIds = robotInfo.robotCookActionWrap.itemIds.stream().filter(id -> id != item.getItemId()).collect(Collectors.toSet());
//        return robotInfo.robotCookActionWrap.itemIds.isEmpty();
//    }
//
//    public static boolean checkHandicraftItems(RobotInfo robotInfo,PBItem item) {
//        robotInfo.handicraftCmdActionWrap.itemIds = robotInfo.handicraftCmdActionWrap.itemIds.stream().filter(id -> id != item.getItemId()).collect(Collectors.toSet());
//        return robotInfo.handicraftCmdActionWrap.itemIds.isEmpty();
//    }
//
//    public static boolean checkSpinItems(RobotInfo robotInfo,PBItem item) {
//        robotInfo.robotSpinCmdActionWrap.itemIds = robotInfo.robotSpinCmdActionWrap.itemIds.stream().filter(id -> id != item.getItemId()).collect(Collectors.toSet());
//        return robotInfo.robotSpinCmdActionWrap.itemIds.isEmpty();
//    }
//
//    public static boolean checkEquipStrengthItems(RobotInfo robotInfo,PBItem item) {
//        robotInfo.robotEquipActionWrap.strengthItemId = robotInfo.robotEquipActionWrap.strengthItemId.stream().filter(id -> id != item.getItemId()).collect(Collectors.toSet());
//        return robotInfo.robotEquipActionWrap.strengthItemId.isEmpty();
//    }
//
//    public static void startPing(KcpSession session) {
//        RobotInfo robotInfo = RobotManager.get(session);
//        if(Objects.isNull(robotInfo) || robotInfo.logout) return;
//        ByteBuf buf = new ByteBuf(1);
//        buf.writeByte((byte) 0x02);
//        if(!session.isInvalid()) session.send(buf.toArray());
//    }
//}
